﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.Admin.Common;
using FortuneHeavenBAL;
using FortuneHeavenCommon.DataMap;
using FortuneHeavenCommon.ComMethod;

namespace FortuneHeaven.Admin.Pages.Statistic
{
    public partial class AreaUserScoreStatistic : FortuneHeaven.Admin.Common.PageBase
    {
        public string Province;
        public string City;
        public override string PageID
        {
            get { return "F67"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblDeptName.Text = "区运营商查询系统";
            this.usPager.PagerChanged += new Admin.Controls.Pagination.PagerChangeHandler(usPager_PagerChanged);
            //if (AuthorityCenter.IsAdmin)
            //{
                Province = Request["slProvince"];
                City = Request["slCity"];
            //}
            //else
            //{
            //    AdminUserBO userbo = new AdminUserBO();
            //    AdminUser user = userbo.GetInfo(AuthorityCenter.CurrentUserID);
            //    Province = user.ProvinceFilter;
            //    City = user.CityFilter;
            //}
            if (!this.IsPostBack)
            {
                this.drpPagerSize.Items.Clear();
                this.drpPagerSize.Items.Add(new ListItem("每页10行", "10"));
                this.drpPagerSize.Items.Add(new ListItem("每页20行", "20"));
                this.drpPagerSize.Items.Add(new ListItem("每页50行", "50"));

                //if (!string.IsNullOrEmpty(Request["orderid"]))
                //{
                //    this.txtOrderID.Text = Request["orderid"];
                //}

                //if (!AuthorityCenter.IsAdmin)
                //{
                //    AdminUserBO userbo = new AdminUserBO();
                //    AdminUser user = userbo.GetInfo(AuthorityCenter.CurrentUserID);
                //    this.spSearch.Visible = false;
                //    this.btnSearch.Visible = false;
                //    this.lbLocation.Visible = true;
                //    this.lbLocation.Text = "省:" + (user.ProvinceFilter != null ? user.ProvinceFilter : "") + "&nbsp;&nbsp;&nbsp; 城市:" + (user.CityFilter != null ? user.CityFilter : "") + "&nbsp;&nbsp;&nbsp; ";
                //}

                if (!string.IsNullOrEmpty(Request["pagesize"]))
                {
                    this.drpPagerSize.SelectedIndex = int.Parse(Request["pagesize"]);
                }
                else
                {
                    this.drpPagerSize.SelectedValue = "10";
                }

                if (!string.IsNullOrEmpty(Request["current"]))
                {
                    ResetList(int.Parse(Request["current"]));
                }
                else
                {
                    ResetList();
                }
                //this.lvNews.ItemCommand += new EventHandler<ListViewCommandEventArgs>(lvNews_ItemCommand);

            }
        }
        private void usPager_PagerChanged(object sender, int currentpage)
        {
            Refresh();
        }

        public void Refresh()
        {
            AreaUserScoreBO giftorder = new AreaUserScoreBO();
            lvNews.DataSource = giftorder.GetList(this.usPager.CurrentPageIndex, int.Parse(this.drpPagerSize.SelectedValue),  Province ,City);
            lvNews.DataBind();
        }

        protected void drpPagerSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList()
        {
            ResetList(1);
        }

        public void SearchValue(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList(int current)
        {
            AreaUserScoreBO giftorder = new AreaUserScoreBO();
            this.usPager.RecordCount = giftorder.GetTotalSize(Province, City);
            this.usPager.PageSize = int.Parse(this.drpPagerSize.SelectedValue);
            this.usPager.Initial();
            this.usPager.CurrentPageIndex = 1;
        }
        public void GenerateExcel(object sender, EventArgs e)
        {
            List<string> names = new List<string>();
            List<string> cols = new List<string>();
            AreaUserScoreBO giftorder = new AreaUserScoreBO();
            names.Add("用户名");
            names.Add("游戏ID");
            names.Add("地区");
            names.Add("游戏时间");
            names.Add("登陆次数");
            names.Add("充值总积分");
            names.Add("玩家当前总额");
            names.Add("玩家赠送总积分");
            names.Add("净消耗");

            cols.Add("Accounts");
            cols.Add("GameID");
            cols.Add("Area");
            cols.Add("PlayTimeFormat");
            cols.Add("GameLogonTimes");
            cols.Add("ChargeValue");
            cols.Add("Total");
            cols.Add("GiveScore");
            cols.Add("GameUsedScore");
            try
            {
                List<AreaUserScore> contents = giftorder.GetList(Province, City);
                if (contents != null && contents.Count > 0)
                {
                    foreach (AreaUserScore a in contents)
                    {
                        a.PlayTimeFormat = UtilMethod.GetTimeByInt(a.PlayTimeCount);
                    }
                    ExcelGenerate.ExportExcel<AreaUserScore>(this.Response, names, cols, contents);
                }
                else
                {
                    ShowCurError("没有数据可以导出");
                }
            }
            catch
            {
                ShowCurError("生成Excel出错");
            }
        }
    }
}